package com.skivingcloud.admin.sys.service.impl;

import com.skivingcloud.admin.sys.entity.SysBusinessType;
import com.skivingcloud.admin.sys.mapper.SysBusinessTypeMapper;
import com.skivingcloud.admin.sys.service.ISysBusinessTypeService;
import com.skivingcloud.common.utils.PageUtils;
import com.skivingcloud.common.utils.UuidUtil;

import net.sf.json.JSONObject;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 业务类型定义 服务实现类
 * </p>
 *
 * @author skivingcloud
 * @since 2022-07-04
 */
@Service
public class SysBusinessTypeServiceImpl extends ServiceImpl<SysBusinessTypeMapper, SysBusinessType> implements ISysBusinessTypeService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		PageUtils pageUtils = PageUtils.getPageInfo(params);
		Page<SysBusinessType> p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getLimit());
		SysBusinessType sysBusinessType = (SysBusinessType) JSONObject.toBean(
				JSONObject.fromObject(params.get("dataForm")),
				SysBusinessType.class);
		QueryWrapper<SysBusinessType> queryWrapper = new QueryWrapper<>();
		if (StringUtils.isNotBlank(sysBusinessType.getTypeCode())) {
			queryWrapper.like("type_code", "%" + sysBusinessType.getTypeCode() + "%");
		}
		if (StringUtils.isNotBlank(sysBusinessType.getTypeName())) {
			queryWrapper.like("type_name", "%" + sysBusinessType.getTypeName() + "%");
		}
		this.baseMapper.selectList(queryWrapper);
		pageUtils = new PageUtils(p);
		return pageUtils;
	}

	@Override
	public void add(SysBusinessType sysBusinessType) {
		sysBusinessType.setId(UuidUtil.get32UUID());
		this.baseMapper.insert(sysBusinessType);
	}

	@Override
	public void update(SysBusinessType sysBusinessType) {
		this.baseMapper.updateById(sysBusinessType);
	}

	@Override
	public void deleteBatch(String[] ids) {
		this.baseMapper.deleteBatchIds(Arrays.asList(ids));
	}

	@Override
	public SysBusinessType selectById(String id) {
		return this.baseMapper.selectById(id);
	}

	@Override
	public List<SysBusinessType> getBusinessTypeList() {
		QueryWrapper<SysBusinessType> queryWrapper = new QueryWrapper<>();
		return this.baseMapper.selectList(queryWrapper);
	}

}
